
package backupUtility;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class UserInput extends javax.swing.JFrame {

    private ArrayList<File> selectedFiles;

    public UserInput(ArrayList<File> selectedFiles){
        this.selectedFiles = selectedFiles;
        initComponents();
    }
    
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        scheduleField = new javax.swing.JTextField();
        classCodeField = new javax.swing.JTextField();
        passwordField = new javax.swing.JPasswordField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/backupUtility/acceptD.jpg"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(480, 310, 250, 85);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/backupUtility/cancelD.jpg"))); // NOI18N
        getContentPane().add(jButton2);
        jButton2.setBounds(480, 405, 250, 85);
        getContentPane().add(scheduleField);
        scheduleField.setBounds(20, 440, 330, 30);
        getContentPane().add(classCodeField);
        classCodeField.setBounds(20, 240, 330, 30);
        getContentPane().add(passwordField);
        passwordField.setBounds(410, 240, 300, 30);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/backupUtility/details.jpg"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(0, 0, 800, 600);

        setSize(new java.awt.Dimension(816, 639));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if(classCodeField.getText().equals("") || 
          scheduleField.getText().equals("") ||
          passwordField.getText().equals("")){
            JOptionPane.showMessageDialog(null,"Enter a value for all fields!");
        }else{
            String classCode = classCodeField.getText();
            String schedule = scheduleField.getText();
            
         String regx = "/\\*;?<' :>|";
            char[] ca = regx.toCharArray();
             for (char c : ca) {
             classCode = classCode.replace(""+c, "");
             schedule = schedule.replace(""+c, "");
         }

             String folderName = classCode+ " - " +schedule;
             String password = passwordField.getText();
        try {
            new BackupLogic(selectedFiles, folderName, password);
        } catch (IOException ex) {
            Logger.getLogger(UserInput.class.getName()).log(Level.SEVERE, null, ex);
        }
        }
        new BackupUtilityUI().setVisible(true);
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

   public static void main(ArrayList<File> selectedFiles) {
        new UserInput(selectedFiles).setVisible(true);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField classCodeField;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPasswordField passwordField;
    private javax.swing.JTextField scheduleField;
    // End of variables declaration//GEN-END:variables
}
